/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import java.util.ArrayList;
import local.ConfigurationFacadeLocal;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import model.Configuration;

/**
 *
 * @author Randy
 */
@Stateless
public class ConfigurationFacade implements ConfigurationFacadeLocal {

    @PersistenceContext(unitName = "IEMPPU")
    private EntityManager em;

    @Override
    public ArrayList<Configuration> getConfigurations() {
        Query query = em.createQuery("SELECT c FROM Configuration c");

        ArrayList<Configuration> cList = new ArrayList<Configuration>();

        for (Object obj : query.getResultList()) {
            Configuration c = (Configuration) obj;
            cList.add(c);
        }

        return cList;
    }

    @Override
    public void updateConfiguration(Long config_id, String status) {
        Configuration c = em.find(Configuration.class, config_id);

        c.setStatus(Configuration.ConfigurationStatus.valueOf(status));
        em.merge(c);
    }

    @Override
    public Configuration find(long config_id) {
        return em.find(Configuration.class, config_id);
    }
}
